package com.jinzhu.common.httpclient;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.NameFilter;
import com.alibaba.fastjson.serializer.SerializerFeature;


import java.io.IOException;

/**
 * 实例
 */
public class test {




    public void postJson() throws IOException {
        HttpRequestConfig config = HttpRequestConfig.create().url("http://192.168.1.107:9018/takeout/order/hello")
                .httpEntityType(HttpEntityType.ENTITY_STRING)
                .json("{\"name\",\"金柱\"}");
        HttpRequestResult result = HttpClientUtils.post(config);
        System.out.println(result.getResponseText());
    }


    public void get() throws IOException {
        HttpRequestConfig config = HttpRequestConfig.create().url("http://localhost:8080/testSendPostDataByMap");
        HttpRequestResult result = HttpClientUtils.get(config);
        System.out.println(result.getResponseText());
    }


    public void post() throws IOException {

//        //创建订单
//        Obj obj = new Obj();
//        obj.setAuth(new Auth(10000001, 1528793155, "d22e6c489d8d4969234fbeb865decd53"));
//        obj.setData(new OrderCreateData("STORE-123",
//                "201806121528793155",
//                "1234",
//                1528793155,
//                "ZEEK_DELIVERY",
//                2,
//                "2018-07-24 18:54:07",
//                "Please dial the customer when arrive reception",
//                "nihao",
//                2,
//                new Receive("Guiying Yao",
//                        "63632752",
//                        "65",
//                        null,
//                        "22.3902837102,114.0042115195",
//                        "#12-456, Woodlands, Singapore, 730779"),
//                new OrderDetail(200),
//                new Meta()));
//        String s = ExcludeJsonProperties.excludeProperties(obj, new String[]{"receive", "order_detail", "meta", "auth"});
//        System.out.println(s);
//        HttpRequestConfig config = HttpRequestConfig.create().url("https://ap1-open-api.zeek.one/v1.3/order/takeaway/merchants/supported").json(HttpJsonUtil.parseEntityToJson(obj));
//        HttpRequestResult result = HttpClientUtils.post(config);
//        System.out.println(result.getResponseText());

    }


    public void postByte() throws IOException {
        HttpRequestConfig config = HttpRequestConfig.create().url("http://localhost:8090/peoples/body")
                .httpEntityType(HttpEntityType.ENTITY_BYTES)
                .bytes("{\"name\",\"金柱\"}".getBytes("UTF-8"));
        HttpRequestResult result = HttpClientUtils.post(config);
        System.out.println(result.getResponseText());
    }

    public void t() throws Exception {


//        obj.setData(new SendToMerchant(
//                new Meta(),
//                "abc-brand",
//                "",
//                "22.3902837102,114.0042115195"
//
//                ));

        //按照zeek文档格式排除非数字和字符的json字段并且根据json首字段排序,然后进行MD5加密之后将加密后的签名放入auth中
//        Auth auth = ZeekAuthSignature.authSignatrue(obj, "meta","auth");
//        obj.setAuth(auth);
        //转换成json字符串并且序列化美观度打印以及排序 格式化--PrettyFormat 排除为null--WriteMapNullValue 字母排序--MapSortField
//        String json = JSONObject.toJSONString(obj, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.MapSortField);
//        HttpRequestConfig config = HttpRequestConfig
//                .create()
//                .url("https://sandbox-ap1-open-api.zeek.one/v1.3/order/takeaway/merchants/supported")
//                .httpEntityType(HttpEntityType.ENTITY_JSON)
//                .json(json);





//        JSONObject jsonObject = JSONObject.parseObject(HttpClientUtils.post(config).getResponseText());
//
//
//        JSONObject jsonObjects = JSONObject.parseObject(jsonObject.get("data").toString());
//        System.out.println(jsonObject.getJSONObject("data"));
//        System.out.println(jsonObjects.getJSONArray("merchants"));
//        SendToMerchantCallback data = JSONObject.parseObject(jsonObject.getJSONObject("data").toString(), SendToMerchantCallback.class);
//        System.out.println(data.getStatus());
//        for (SendToMerchantCallback.Merchants merchant : data.getMerchants()) {
//            System.out.println(merchant.getMerchant_id());
//            System.out.println(merchant.getPrediction().getQuote_time());
//        }

    }

}
